//
//  OPDataPickerViewController.m
//  OnePiece
//
//  Created by lanou on 15/11/2.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPDataPickerViewController.h"

@interface OPDataPickerViewController ()
@end

@implementation OPDataPickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _picker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 200)];
    [self.view addSubview:_picker];
    
    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [btn setTitle:@"取消" forState:(UIControlStateNormal)];
    btn.frame = CGRectMake(30, 30, 60, 30);
    [btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    btn.layer.cornerRadius = 5;
    btn.backgroundColor = [UIColor colorWithRed:0.893 green:0.618 blue:0.346 alpha:1.000];
    [btn addTarget:self action:@selector(cancal) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:btn];
    
    UIButton *btn1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [btn1 setTitle:@"完成" forState:(UIControlStateNormal)];
    [btn1 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    btn1.frame = CGRectMake(SCREEN_WIDTH - 90, 30, 60, 30);
    btn1.layer.cornerRadius = 5;
    btn1.backgroundColor = [UIColor colorWithRed:0.893 green:0.618 blue:0.346 alpha:1.000];
    [btn1 addTarget:self action:@selector(down) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:btn1];
}

- (void)cancal
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)down
{
    [self dismissViewControllerAnimated:YES completion:^{
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy年MM月dd日HH时mm分ss秒"];
        NSString *str = [formatter stringFromDate:_picker.date];
        [str substringWithRange:NSMakeRange(0, str.length - 3)];
        self.dataBlock(str);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
